package jdk8_new_features;

import org.apache.camel.spring.remoting.CamelServiceExporter;
import org.apache.log4j.helpers.ThreadLocalMap;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

public class StreamPractice {

    public static void main(String [] arg0){
        // IntStream 练习
        IntStreamDemo();

        if(2>1)
            System.out.println("1111111");
            System.out.println("222222");
        System.out.println("555555");
        if(2>3){
            System.out.println("33333");
        }

        System.out.println("444444");

        TreeMap<Integer,Object> treeMap = new TreeMap<>(new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o1.compareTo(o2);
            }
        });




//        Thread a = Thread.currentThread();
//        ThreadLocal<String> threadLocal = new ThreadLocal<String>();
//        threadLocal.set("张三");
//        threadLocal.get();



        LocalDate.now();
        LocalTime.now();
        LocalDateTime.now();

    }


    public static void IntStreamDemo(){
        // rang()  范围左开右开，从0 到 4 ，不包括5
        IntStream.range(0,5).forEach(a-> System.out.println("--- a=" + a));

        // rang()  范围左闭右开，从0 到 5 ，包括5
        IntStream.rangeClosed(0,5).forEach(b-> System.out.println("--- a=" + b));

        //sum()  求和
        int sum = IntStream.rangeClosed(0,5).sum();
        System.out.println("--- sum=" + sum);

        //sorted() 排序
        IntStream.of(2,4,1,6,9,21,45,8).sorted().forEach(c-> System.out.println("--- c=" + c));

        //empty() : 空的流集合
        IntStream.empty().forEach(e -> System.out.println("--- e=" + e));

        //average() 求平均值
        OptionalDouble optionalDouble = IntStream.of(2,5,7,9).average();
        System.out.println("--- average=" + optionalDouble);

        //filter() 过滤器              取出所有的奇数
        IntStream.of(2,3,4,5,6,7).filter(a -> a%2 == 1).forEach( r -> System.out.println("--- r=" + r));


    }





}
